var express = require('express');
var router = express.Router();

const { uploadFiles } = require('../utils/uploadFiles');

router.post('/upload', function (req, res, next) {
    const upload = uploadFiles({
        path: './public/temp',  // 设置上传成功后的图片存储路径
        key: 'file', // 与前端 formData.append('file', files[0]); 中的 file 相匹配
        size: 1000
    });
    upload(req, res, (err) => {
        if (err) {
            console.log('图片上传失败');
        } else {
            console.log('图片上传成功', req.files);
            res.send({
                message: '图片上传成功',
                status: 1,
                data: req.files[0].filename
            });
        }
    });
});

module.exports = router;
